/**
 * 布局信息
 */
import { defineStore } from 'pinia';
import { portal } from '@/types/common/setting.ts';
import { Layout, LayoutMenu } from '@/types/layout';

export const layout = defineStore('layout', {
  state(): portal {
    return {
      layout: {
        id: 0,
      }, // 布局
      menu: {
        id: 0,
        name: '',
      }, // 当前激活的菜单id
    };
  },
  getters: {
    layout: (state) => (state.layout === undefined ? { id: 0 } : state.layout),
    menu: (state) => (state.menu === undefined ? { id: 0, name: '' } : state.menu),
  },
  actions: {
    // 设置布局
    setLayout(layout: Layout) {
      this.$state.layout = layout;
    },
    setMenu(menu: LayoutMenu) {
      this.$state.menu = menu;
    },
  },
  persist: {
    storage: window.localStorage,
  },
});
